<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改房间管理')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />

</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-room-edit" th:object="${room}">
            <input name="id" th:field="*{id}" type="hidden">
            <input name="rate" th:field="*{rate}" class="form-control" type="hidden">
            <input name="headpic" id="headpic" th:value="${room.headpic} ?: '/img/fangjian.jpg'" class="form-control" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">头像：</label>
                <div class="fileinput fileinput-new col-sm-8" data-provides="fileinput">
                    <div class="fileinput-new thumbnail" style="width: 140px; height: 140px;">
                        <img th:src="${room.headpic} ?: '/img/fangjian.jpg'" id="uploadImg">
                    </div>
                    <div>
                        <span class="btn btn-white btn-file">
                            <span class="fileinput-new">选择图片</span>
                            <span class="fileinput-exists">更改</span>
                            <input type="file" name="filePath" id="filePath" onchange="uploadFile()" accept="image/*">
                        </span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">房间类型：</label>
                <div class="col-sm-8">
                    <select name="roomTypeId" class="form-control m-b" required >
                        <option th:each="option : ${roomType}" th:value="${option.id}" th:text="${option.type}"
                                th:field="*{roomTypeId}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">可住人数：</label>
                <div class="col-sm-8">
                    <input name="count" th:field="*{count}" class="form-control" type="number" onchange="if(/\D/.test(this.value)){this.value='1';}" required>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">床位数：</label>
                <div class="col-sm-8">
                    <input name="bedCount" th:field="*{bedCount}" class="form-control" type="number" onchange="if(/\D/.test(this.value)){this.value='1';}" required>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">房间号：</label>
                <div class="col-sm-8">
                    <input name="roomNumber" th:field="*{roomNumber}" class="form-control" type="text" required>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">价格：</label>
                <div class="col-sm-8">
                    <input name="price" th:field="*{price}" class="form-control" type="number" onchange="if(/\D/.test(this.value)){this.value='1';}" required>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">房间介绍：</label>
                <div class="col-sm-8">
                    <textarea name="content" th:field="*{content}" class="form-control" type="text"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">房间状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('ylrc_room_status')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否是钟点房：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('ylrc_is_time_limit')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="isTimeLimit" th:value="${dict.dictValue}"
                               th:field="*{isTimeLimit}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jasny-bootstrap-js" />

    <script type="text/javascript">


        var prefix = ctx + "hotel/room";
        $("#form-room-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-room-edit').serialize());
            }
        }

        function uploadFile() {
            var formData = new FormData();
            if ($('#filePath')[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }



            formData.append('file', $('#filePath')[0].files[0]);
            $.ajax({
                url: "/common/upload/image",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    if(result.code == 0)
                    {
                        $("#headpic").val(result.fileName);
                        $("#uploadImg").attr("src", result.fileName);
                    }
                    else{
                        $.modal.alertError("上传失败");
                    }
                }
            });
        }
    </script>
</body>
</html>